<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<div id="app">
  <cpn></cpn>
</div>
<template id="cpn">
  <div>
    <ccpn></ccpn>
  </div>
</template>
<template id="ccpn">
  <div>
    <h3>我的ccpn组件</h3>
    <button @click="btnClick">按钮</button>
  </div>
</template>
<script src="../js/vue.js"></script>
<script>
  const vm = new Vue({
    el: '#app',
    data: {
      name: '侯世龙'
    },
    components: {
      cpn: {
        template: '#cpn',
        data() {
          return {
            name: '陈健'
          }
        },
        components: {
          ccpn: {
            template: '#ccpn',
            methods: {
              btnClick() {
                //访问父组件
                console.log(this.$parent);//父组件对象为VueComponent
                console.log(this.$parent.name);
                //访问跟组件
                console.log(this.$root)//跟组件对象为Vue
                console.log(this.$root.name)
              }
            }
          }
        }
      }
    }
  })
</script>

</body>
</html>